def compression(chars: list[str]):
    i = 0
    pointer = 0

    while i < len(chars):
        count = 0
        curr_char = chars[i]

        while i < len(chars) and chars[i] == curr_char:
            i += 1
            count += 1

        chars[pointer] = curr_char
        pointer += 1
        if count > 1:
            for char in str(count):
                chars[pointer] = char
                pointer += 1

    return chars[:pointer]
